<?php
// +----------------------------------------------------------------------
// | QSCMS
// +----------------------------------------------------------------------
// | Copyright (c)  2025 https://www.qqss.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed QSCMS is not free software, commercial use must purchase official license from official website to avoid unnecessary legal disputes.
// +----------------------------------------------------------------------
// | Author: Contract 990504246@qq.com
// +----------------------------------------------------------------------

namespace app\common\model;

use think\Model;


class AdminLog extends Model
{

  protected $autoWriteTimestamp = true;
  protected $updateTime = false;

  public function searchUsernameAttr($query, $value, $data)
  {
    $query->where('username', '=', $value);
  }

  public function searchIpAttr($query, $value, $data)
  {
    $query->where('ip', '=', $value);
  }

  public function searchActionAttr($query, $value, $data)
  {
    $query->where('action', '=', $value);
  }

  public function searchDateRangeAttr($query, $value, $data)
  {
    if (empty(trim($value[0])) || empty(trim($value[1]))) {
      return;
    }
    if ($value[0] == $value[1]) {
      $query->whereTime('create_time', $value[0]);
      return;
    }
    $query->whereBetweenTime('create_time', $value[0], $value[1]);
  }
}